<!doctype html>
<html lang="">
<head>
  <meta charset="utf-8">
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>st</title>

  <link rel="apple-touch-icon" href="apple-touch-icon.png">
  <!-- Place favicon.ico in the root directory -->

  <!-- build:css styles/vendor.css -->
  <!-- bower:css -->
  <link rel="stylesheet" href="/bower_components/datatables/media/css/dataTables.bootstrap.css" />
  <!-- endbower -->
  <!-- endbuild -->

  <!-- build:css styles/main.css -->
  <link rel="stylesheet" href="styles/main.css">
  <!-- endbuild -->

</head>
<body>
<!--[if IE]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade
  your browser</a> to improve your experience.</p>
<![endif]-->

<div class="container">

  <div class="edit-box">
    <form action="/api/admin" class="add-admin-form form-horizontal" role="form" method="post">
      <!--<div class="form-group">-->
        <!--<label class="col-xs-3 control-label sr-only" for="id">ID</label>-->
        <!--<div class="col-xs-9">-->
          <!--<input class="form-control input-sm" id="id" name="id" placeholder="请输入ID" type="hidden">-->
        <!--</div>-->
      <!--</div>-->
      <div class="form-group">
        <label class="col-xs-3 control-label" for="username">登录帐号</label>
        <div class="col-xs-9">
          <input class="form-control input-sm" id="username" name="username" placeholder="请输入姓名">
        </div>
      </div>
      <div class="form-group">
        <label class="col-xs-3 control-label" for="password">登录密码</label>
        <div class="col-xs-9">
          <input type="password" class="form-control input-sm" id="password" name="password" placeholder="留空则不修改">
        </div>
      </div>
      <div class="form-group">
        <label class="col-xs-3 control-label" for="confirm">确认密码</label>
        <div class="col-xs-9">
          <input type="password" class="form-control input-sm" id="confirm" name="confirm" placeholder="确认密码">
        </div>
      </div>
      <div class="form-group">
        <label class="col-xs-3 control-label" for="name">姓名</label>
        <div class="col-xs-9">
          <input class="form-control input-sm" id="name" name="name" placeholder="请输入姓名">
        </div>
      </div>
      <div class="col-xs-9 col-xs-offset-3">
        <button id="add-admin-btn" type="submit" class="btn btn-primary btn-block">立即添加</button>
      </div>
    </form>
  </div>
</div>


<!-- build:js scripts/vendor.js -->
<!-- bower:js -->
<script src="/bower_components/jquery/dist/jquery.js"></script>
<script src="/bower_components/datatables/media/js/jquery.dataTables.js"></script>
<script src="/bower_components/datatables/media/js/dataTables.bootstrap.js"></script>
<script src="/bower_components/layer/src/layer.js"></script>
<!-- endbower -->
<!-- endbuild -->

<!-- build:js scripts/plugins.js -->
<script src="/bower_components/bootstrap-sass/assets/javascripts/bootstrap/affix.js"></script>
<script src="/bower_components/bootstrap-sass/assets/javascripts/bootstrap/alert.js"></script>
<script src="/bower_components/bootstrap-sass/assets/javascripts/bootstrap/dropdown.js"></script>
<script src="/bower_components/bootstrap-sass/assets/javascripts/bootstrap/tooltip.js"></script>
<script src="/bower_components/bootstrap-sass/assets/javascripts/bootstrap/modal.js"></script>
<script src="/bower_components/bootstrap-sass/assets/javascripts/bootstrap/transition.js"></script>
<script src="/bower_components/bootstrap-sass/assets/javascripts/bootstrap/button.js"></script>
<script src="/bower_components/bootstrap-sass/assets/javascripts/bootstrap/popover.js"></script>
<script src="/bower_components/bootstrap-sass/assets/javascripts/bootstrap/carousel.js"></script>
<script src="/bower_components/bootstrap-sass/assets/javascripts/bootstrap/scrollspy.js"></script>
<script src="/bower_components/bootstrap-sass/assets/javascripts/bootstrap/collapse.js"></script>
<script src="/bower_components/bootstrap-sass/assets/javascripts/bootstrap/tab.js"></script>
<!-- endbuild -->

<!-- build:js scripts/main.js -->
<script src="scripts/main.js"></script>
<!-- endbuild -->

<script>

  $('.add-admin-form').submit(function () {
    var postData = $(this).serializeArray();
    add(postData)
    return false;
  });

  function add(data) {
    $("#add-admin-btn").addClass('disabled');
    $.ajax({
      type: 'post',
      url: '/api/admin',
      data: data,
      xhrFields: {
        withCredentials: true
      },
      crossDomain: true,
      success: function (result) {
        if (result.code === 1) {
          layer.msg(result.info, {icon: 6},function () {
            parent.location.reload()
          })
        } else {
          layer.msg(result.info, {icon: 5})
        }
      },
      complete:function () {
        $("#add-stu-btn").removeClass('disabled');
      },
      dataType: 'json'
    })
  }

</script>
</body>
</html>
